<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<!-- modify by zhangwei -->
<!-- 百度站长 -->
<meta name="baidu-site-verification" content="MdPKZBgY0U">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">



  <meta name="google-site-verification" content="8DKRuNxJDPU2k6cNyVhLe_eSqGk-R8oiYk8iKMg5gwI">














  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/uploads/favicon.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/uploads/favicon.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/uploads/favicon.ico?v=5.1.4">


  <link rel="mask-icon" href="/uploads/favicon.ico?v=5.1.4" color="#222">





  <meta name="keywords" content="Android,SQLite,">





  <link rel="alternate" href="/atom.xml" title="班德尔城" type="application/atom+xml">






<meta name="description" content="Android SQLite，是一款轻量级的关系型数据库。在很多嵌入式设备都用来存储数据。">
<meta name="keywords" content="Android,SQLite">
<meta property="og:type" content="article">
<meta property="og:title" content="Android黄金篇-SQLite数据库">
<meta property="og:url" content="https://tiimor.cn/Android黄金篇-SQLite数据库/index.html">
<meta property="og:site_name" content="班德尔城">
<meta property="og:description" content="Android SQLite，是一款轻量级的关系型数据库。在很多嵌入式设备都用来存储数据。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://cdn.tiimor.cn/images/sqlite.jpg">
<meta property="og:updated_time" content="2019-03-17T06:47:42.375Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android黄金篇-SQLite数据库">
<meta name="twitter:description" content="Android SQLite，是一款轻量级的关系型数据库。在很多嵌入式设备都用来存储数据。">
<meta name="twitter:image" content="http://cdn.tiimor.cn/images/sqlite.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '3AUIZWGETM',
      apiKey: '5fcd6d51d892fffe3480c5b37f5fd4fa',
      indexName: 'Tiimor',
      hits: {"per_page":8},
      labels: {"input_placeholder":"搜索","hits_empty":"未发现与「${query}」相关的内容","hits_stats":"${hits} 条相关条目，使用了 ${time} 毫秒"}
    }
  };
</script>



  <link rel="canonical" href="https://tiimor.cn/Android黄金篇-SQLite数据库/">





  <title>Android黄金篇-SQLite数据库 | 班德尔城</title>
  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-96457043-1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?abb97f8f68c9e5eb2217d3111c64e696";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

  <!-- modify by zhangwei -->
  <!-- 下雪的动画 -->
  <div class="canvas-snow">
    <canvas id="canvas" style="margin: 0;  padding: 0;top:0; left: 0; right: 0; background: transparent; position: absolute;" width="1366" height="105"></canvas>
      <script>

      var canvasBgImg = {
        start: function () {
          this.canvas = document.getElementById('canvas')
          this.ctx = this.canvas.getContext("2d")
          this.canvas.width = window.innerWidth
          this.canvas.height = 105
          this.starList = []
        },
        drawLine: function (ctx, x1, y1, x2, y2) {
          ctx.beginPath()
          ctx.strokeStyle = '#ffffff'
          ctx.lineTo(x1, y1)
          ctx.lineTo(x2, y2)
          ctx.stroke()
        },
        canvasSingleSnow: function (snowSize) {
          var singleSnow = document.createElement('canvas'),
            ctxSingle = singleSnow.getContext('2d')
          singleSnow.setAttribute('width', snowSize * 2)
          singleSnow.setAttribute('height', snowSize * 2)
          for (var i = 0; i < 6; i++) {
            ctxSingle.save()
            ctxSingle.translate(snowSize, snowSize)
            ctxSingle.rotate(Math.PI * 2 * i / 6)
            this.drawLine(ctxSingle, 0, 0, snowSize, 0)
            ctxSingle.restore()
          }
          return singleSnow
        },
        canvasAllSnow: function (centerSnow) {
          var canvasSnow = document.createElement('canvas'),
            ctxSnow = canvasSnow.getContext('2d'),
            bigSnow = this.canvasSingleSnow(centerSnow),
            smallSnow = this.canvasSingleSnow(centerSnow / 3),
            sizeSnow = centerSnow * 3 / 5,
            rSnow = centerSnow - sizeSnow / 2
          canvasSnow.setAttribute('width', centerSnow * 2)
          canvasSnow.setAttribute('height', centerSnow * 2)
          ctxSnow.drawImage(bigSnow, 0, 0, bigSnow.width, bigSnow.height, 0, 0, centerSnow * 2, centerSnow * 2)
          for (var i = 0; i < 6; i++) {
            ctxSnow.save()
            ctxSnow.translate(centerSnow, centerSnow)
            ctxSnow.rotate(Math.PI * 2 * i / 6)
            ctxSnow.drawImage(smallSnow, 0, 0, smallSnow.width, smallSnow.height, rSnow - sizeSnow / 2,
              -sizeSnow / 2, sizeSnow, sizeSnow)
            ctxSnow.restore()
          }
          return canvasSnow
        },
        init: function () {
          this.start()
          for (var i = 0; i < 75; i++) {
            this.starList.push({
              drawFunc: this.canvasAllSnow(15),
              width: Math.random() * this.canvas.width,
              height: Math.random() * this.canvas.height,
              speed: Math.random() * 1.5 + .5,
              scale: Math.random() * 12 + 5,
              angel: 0
            })
          }
          var self = this,
            loop = function () {
              self.ctx.clearRect(0, 0, self.canvas.width, self.canvas.width)
              for (var i = 0; i < 75; i++) {
                self.ctx.save()
                self.starList[i].height = self.starList[i].height + self.starList[i].speed
                self.starList[i].angel += 2
                self.ctx.translate(self.starList[i].width, self.starList[i].height)
                self.ctx.rotate(self.starList[i].angel * Math.PI / 360)
                self.ctx.translate(-self.starList[i].width, -self.starList[i].height)
                self.ctx.drawImage(self.starList[i].drawFunc, 0, 0,
                  self.starList[i].drawFunc.width, self.starList[i].drawFunc.height,
                  self.starList[i].width - self.starList[i].scale / 2,
                  self.starList[i].height - self.starList[i].scale / 2,
                  self.starList[i].scale, self.starList[i].scale)
                if (self.starList[i].height > self.canvas.height) {
                  self.starList[i] = Object.assign(self.starList[i], {
                    height: -self.starList[i].scale,
                    width: Math.random() * this.canvas.width
                  })
                }
                self.ctx.restore()
              }
              requestAnimationFrame(loop)
            }
          requestAnimationFrame(loop)
        }
      }
      canvasBgImg.init()
      </script>

    </div>


    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <!-- modify by zhangwei -->
        <!-- 圣诞帽 -->
        <img src="/uploads/santa-hat.png" id="santa" style="height: 41px; position: absolute; left: -40px; top: -20px; transform: rotate(-45deg); z-index: 9000;">

        <span class="logo-line-before"><i></i></span>
        <span class="site-title">班德尔城</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">微笑，简单，奋发</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-guestbook">
          <a href="/guestbook" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-send"></i> <br>
            
            留言
          </a>
        </li>
      
        
        <li class="menu-item menu-item-favourite">
          <a href="/favourite" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-bookmark"></i> <br>
            
            收藏
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  
  <div class="algolia-popup popup search-popup">
    <div class="algolia-search">
      <div class="algolia-search-input-icon">
        <i class="fa fa-search"></i>
      </div>
      <div class="algolia-search-input" id="algolia-search-input"></div>
    </div>

    <div class="algolia-results">
      <div id="algolia-stats"></div>
      <div id="algolia-hits"></div>
      <div id="algolia-pagination" class="algolia-pagination"></div>
    </div>

    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>




    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://tiimor.cn/Android黄金篇-SQLite数据库/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Tiimor">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="班德尔城">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Android黄金篇-SQLite数据库</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-06-18T15:41:14+08:00">
                2017-06-18
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Android联盟/" itemprop="url" rel="index">
                    <span itemprop="name">Android联盟</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/Android黄金篇-SQLite数据库/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count gitment-comments-count" data-xid="/Android黄金篇-SQLite数据库/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/Android黄金篇-SQLite数据库/" class="leancloud_visitors" data-flag-title="Android黄金篇-SQLite数据库">
               <span class="post-meta-divider">|</span>
               <!-- modify by zhangwei -->
               <!-- 去掉阅读的眼睛图标，阅读次数改为℃ -->
			   
                 <span class="post-meta-item-text">热度 </span>
               
                 <span class="leancloud-visitors-count"></span>
				 <span>℃</span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><img src="http://cdn.tiimor.cn/images/sqlite.jpg" alt="SQLite"></p>
<p>Android SQLite&#xFF0C;&#x662F;&#x4E00;&#x6B3E;&#x8F7B;&#x91CF;&#x7EA7;&#x7684;&#x5173;&#x7CFB;&#x578B;&#x6570;&#x636E;&#x5E93;&#x3002;&#x5728;&#x5F88;&#x591A;&#x5D4C;&#x5165;&#x5F0F;&#x8BBE;&#x5907;&#x90FD;&#x7528;&#x6765;&#x5B58;&#x50A8;&#x6570;&#x636E;&#x3002;</p>
<a id="more"></a>
<h1 id="SQLite&#x4ECB;&#x7ECD;"><a href="#SQLite&#x4ECB;&#x7ECD;" class="headerlink" title="SQLite&#x4ECB;&#x7ECD;"></a>SQLite&#x4ECB;&#x7ECD;</h1><p>SQLite&#x662F;&#x4E00;&#x6B3E;&#x8F7B;&#x91CF;&#x7EA7;&#x7684;&#x5173;&#x7CFB;&#x578B;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x5B83;&#x7684;&#x8FD0;&#x7B97;&#x901F;&#x5EA6;&#x975E;&#x5E38;&#x5FEB;&#xFF0C;&#x5360;&#x7528;&#x8D44;&#x6E90;&#x5F88;&#x5C11;&#xFF0C;&#x901A;&#x5E38;&#x53EA;&#x9700;&#x8981;&#x51E0;&#x767E;K&#x7684;&#x5185;&#x5B58;&#x5C31;&#x8DB3;&#x591F;&#x4E86;&#xFF0C;&#x56E0;&#x800C;&#x7279;&#x522B;&#x9002;&#x5408;&#x5728;&#x79FB;&#x52A8;&#x8BBE;&#x5907;&#x4E0A;&#x4F7F;&#x7528;&#x3002;</p>
<h1 id="SQLite&#x7279;&#x70B9;"><a href="#SQLite&#x7279;&#x70B9;" class="headerlink" title="SQLite&#x7279;&#x70B9;"></a>SQLite&#x7279;&#x70B9;</h1><ul>
<li>&#x8F7B;&#x91CF;&#x7EA7;<br>  &#x4F7F;&#x7528; SQLite &#x53EA;&#x9700;&#x8981;&#x5E26;&#x4E00;&#x4E2A;&#x52A8;&#x6001;&#x5E93;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x4EAB;&#x53D7;&#x5B83;&#x7684;&#x5168;&#x90E8;&#x529F;&#x80FD;&#xFF0C;&#x800C;&#x4E14;&#x90A3;&#x4E2A;&#x52A8;&#x6001;&#x5E93;&#x7684;&#x5C3A;&#x5BF8;&#x60F3;&#x5F53;&#x5C0F;&#x3002;</li>
<li>&#x72EC;&#x7ACB;&#x6027;<br>  SQLite &#x6570;&#x636E;&#x5E93;&#x7684;&#x6838;&#x5FC3;&#x5F15;&#x64CE;&#x4E0D;&#x9700;&#x8981;&#x4F9D;&#x8D56;&#x7B2C;&#x4E09;&#x65B9;&#x8F6F;&#x4EF6;&#xFF0C;&#x4E5F;&#x4E0D;&#x9700;&#x8981;&#x6240;&#x8C13;&#x7684;&#x201C;&#x5B89;&#x88C5;&#x201D;&#x3002;</li>
<li>&#x9694;&#x79BB;&#x6027;<br>  SQLite &#x6570;&#x636E;&#x5E93;&#x4E2D;&#x6240;&#x6709;&#x7684;&#x4FE1;&#x606F;&#xFF08;&#x6BD4;&#x5982;&#x8868;&#x3001;&#x89C6;&#x56FE;&#x3001;&#x89E6;&#x53D1;&#x5668;&#x7B49;&#xFF09;&#x90FD;&#x5305;&#x542B;&#x5728;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x5939;&#x5185;&#xFF0C;&#x65B9;&#x4FBF;&#x7BA1;&#x7406;&#x548C;&#x7EF4;&#x62A4;&#x3002;</li>
<li>&#x8DE8;&#x5E73;&#x53F0;<br>  SQLite &#x76EE;&#x524D;&#x652F;&#x6301;&#x5927;&#x90E8;&#x5206;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#xFF0C;&#x4E0D;&#x81F3;&#x7535;&#x8111;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x66F4;&#x5728;&#x4F17;&#x591A;&#x7684;&#x624B;&#x673A;&#x7CFB;&#x7EDF;&#x4E5F;&#x662F;&#x80FD;&#x591F;&#x8FD0;&#x884C;&#xFF0C;&#x6BD4;&#x5982;&#xFF1A;Android&#x548C;IOS&#x3002;</li>
<li>&#x591A;&#x8BED;&#x8A00;&#x63A5;&#x53E3;<br>  SQLite &#x6570;&#x636E;&#x5E93;&#x652F;&#x6301;&#x591A;&#x8BED;&#x8A00;&#x7F16;&#x7A0B;&#x63A5;&#x53E3;&#x3002;</li>
<li>&#x5B89;&#x5168;&#x6027;<br>  SQLite &#x6570;&#x636E;&#x5E93;&#x901A;&#x8FC7;&#x6570;&#x636E;&#x5E93;&#x7EA7;&#x4E0A;&#x7684;&#x72EC;&#x5360;&#x6027;&#x548C;&#x5171;&#x4EAB;&#x9501;&#x6765;&#x5B9E;&#x73B0;&#x72EC;&#x7ACB;&#x4E8B;&#x52A1;&#x5904;&#x7406;&#x3002;&#x8FD9;&#x610F;&#x5473;&#x7740;&#x591A;&#x4E2A;&#x8FDB;&#x7A0B;&#x53EF;&#x4EE5;&#x5728;&#x540C;&#x4E00;&#x65F6;&#x95F4;&#x4ECE;&#x540C;&#x4E00;&#x6570;&#x636E;&#x5E93;&#x8BFB;&#x53D6;&#x6570;&#x636E;&#xFF0C;&#x4F46;&#x53EA;&#x80FD;&#x6709;&#x4E00;&#x4E2A;&#x53EF;&#x4EE5;&#x5199;&#x5165;&#x6570;&#x636E;&#x3002;</li>
<li>&#x5F31;&#x7C7B;&#x578B;&#x7684;&#x5B57;&#x6BB5;<br>  &#x540C;&#x4E00;&#x5217;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x53EF;&#x4EE5;&#x662F;&#x4E0D;&#x540C;&#x7C7B;&#x578B;</li>
</ul>
<h1 id="SQLite&#x6570;&#x636E;&#x7C7B;&#x578B;"><a href="#SQLite&#x6570;&#x636E;&#x7C7B;&#x578B;" class="headerlink" title="SQLite&#x6570;&#x636E;&#x7C7B;&#x578B;"></a>SQLite&#x6570;&#x636E;&#x7C7B;&#x578B;</h1><p>SQLite &#x6570;&#x636E;&#x7C7B;&#x578B;&#x662F;&#x4E00;&#x4E2A;&#x7528;&#x6765;&#x6307;&#x5B9A;&#x4EFB;&#x4F55;&#x5BF9;&#x8C61;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x5C5E;&#x6027;&#x3002;SQLite &#x4E2D;&#x7684;&#x6BCF;&#x4E00;&#x5217;&#xFF0C;&#x6BCF;&#x4E2A;&#x53D8;&#x91CF;&#x548C;&#x8868;&#x8FBE;&#x5F0F;&#x90FD;&#x6709;&#x76F8;&#x5173;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x3002;<br>&#x60A8;&#x53EF;&#x4EE5;&#x5728;&#x521B;&#x5EFA;&#x8868;&#x7684;&#x540C;&#x65F6;&#x4F7F;&#x7528;&#x8FD9;&#x4E9B;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x3002;SQLite &#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x66F4;&#x666E;&#x904D;&#x7684;&#x52A8;&#x6001;&#x7C7B;&#x578B;&#x7CFB;&#x7EDF;&#x3002;&#x5728; SQLite &#x4E2D;&#xFF0C;&#x503C;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x4E0E;&#x503C;&#x672C;&#x8EAB;&#x662F;&#x76F8;&#x5173;&#x7684;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x4E0E;&#x5B83;&#x7684;&#x5BB9;&#x5668;&#x76F8;&#x5173;&#x3002;<br>&#x4E00;&#x822C;&#x6570;&#x636E;&#x91C7;&#x7528;&#x7684;&#x56FA;&#x5B9A;&#x7684;&#x9759;&#x6001;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x800C;SQLite&#x91C7;&#x7528;&#x7684;&#x662F;&#x52A8;&#x6001;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x4F1A;&#x6839;&#x636E;&#x5B58;&#x5165;&#x503C;&#x81EA;&#x52A8;&#x5224;&#x65AD;&#x3002;SQLite&#x5177;&#x6709;&#x4EE5;&#x4E0B;&#x4E94;&#x79CD;&#x5E38;&#x7528;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x5B58;&#x50A8;&#x7C7B;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td>NULL</td>
<td>&#x503C;&#x662F;&#x4E00;&#x4E2A; NULL &#x503C;&#x3002;</td>
</tr>
<tr>
<td>INTEGER</td>
<td>&#x503C;&#x662F;&#x4E00;&#x4E2A;&#x5E26;&#x7B26;&#x53F7;&#x7684;&#x6574;&#x6570;&#xFF0C;&#x6839;&#x636E;&#x503C;&#x7684;&#x5927;&#x5C0F;&#x5B58;&#x50A8;&#x5728; 1&#x3001;2&#x3001;3&#x3001;4&#x3001;6 &#x6216; 8 &#x5B57;&#x8282;&#x4E2D;&#x3002;</td>
</tr>
<tr>
<td>REAL</td>
<td>&#x503C;&#x662F;&#x4E00;&#x4E2A;&#x6D6E;&#x70B9;&#x503C;&#xFF0C;&#x5B58;&#x50A8;&#x4E3A; 8 &#x5B57;&#x8282;&#x7684; IEEE &#x6D6E;&#x70B9;&#x6570;&#x5B57;&#x3002;</td>
</tr>
<tr>
<td>TEXT</td>
<td>&#x503C;&#x662F;&#x4E00;&#x4E2A;&#x6587;&#x672C;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x4F7F;&#x7528;&#x6570;&#x636E;&#x5E93;&#x7F16;&#x7801;&#xFF08;UTF-8&#x3001;UTF-16BE &#x6216; UTF-16LE&#xFF09;&#x5B58;&#x50A8;&#x3002;</td>
</tr>
<tr>
<td>BLOB</td>
<td>&#x503C;&#x662F;&#x4E00;&#x4E2A; blob &#x6570;&#x636E;&#xFF0C;&#x5B8C;&#x5168;&#x6839;&#x636E;&#x5B83;&#x7684;&#x8F93;&#x5165;&#x5B58;&#x50A8;&#x3002;</td>
</tr>
</tbody>
</table>
<p><a href="http://www.runoob.com/sqlite/sqlite-data-types.html" target="_blank" rel="noopener">&#x4F20;&#x9001;&#x95E8;</a></p>
<h1 id="SQLiteDatabase&#x7684;&#x4ECB;&#x7ECD;"><a href="#SQLiteDatabase&#x7684;&#x4ECB;&#x7ECD;" class="headerlink" title="SQLiteDatabase&#x7684;&#x4ECB;&#x7ECD;"></a>SQLiteDatabase&#x7684;&#x4ECB;&#x7ECD;</h1><p>Android&#x63D0;&#x4F9B;&#x4E86;&#x521B;&#x5EFA;&#x548C;&#x662F;&#x7528;SQLite&#x6570;&#x636E;&#x5E93;&#x7684;API&#x3002;SQLiteDatabase&#x4EE3;&#x8868;&#x4E00;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#x5BF9;&#x8C61;&#xFF0C;&#x63D0;&#x4F9B;&#x4E86;&#x64CD;&#x4F5C;&#x6570;&#x636E;&#x5E93;&#x7684;&#x4E00;&#x4E9B;&#x65B9;&#x6CD5;&#x3002;&#x5728;Android&#x7684;SDK&#x76EE;&#x5F55;&#x4E0B;&#x6709;sqlite3&#x5DE5;&#x5177;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5229;&#x7528;&#x5B83;&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;&#x3001;&#x521B;&#x5EFA;&#x8868;&#x548C;&#x6267;&#x884C;&#x4E00;&#x4E9B;SQL&#x8BED;&#x53E5;&#x3002;&#x4E0B;&#x9762;&#x662F;SQLiteDatabase&#x7684;&#x5E38;&#x7528;&#x65B9;&#x6CD5;&#x3002;</p>
<table>
<thead>
<tr>
<th>&#x65B9;&#x6CD5;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td>openOrCreateDatabase(String path,SQLiteDatabase.CursorFactory  factory)</td>
<td>&#x6253;&#x5F00;&#x6216;&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;</td>
</tr>
<tr>
<td>insert(String table,String nullColumnHack,ContentValues  values)</td>
<td>&#x63D2;&#x5165;&#x4E00;&#x6761;&#x8BB0;&#x5F55;</td>
</tr>
<tr>
<td>delete(String table,String whereClause,String[]  whereArgs)</td>
<td>&#x5220;&#x9664;&#x4E00;&#x6761;&#x8BB0;&#x5F55;</td>
</tr>
<tr>
<td>query(String table,String[] columns,String selection,String[]  selectionArgs,String groupBy,String having,String  orderBy)</td>
<td>&#x67E5;&#x8BE2;&#x4E00;&#x6761;&#x8BB0;&#x5F55;</td>
</tr>
<tr>
<td>update(String table,ContentValues values,String whereClause,String[]  whereArgs)</td>
<td>&#x4FEE;&#x6539;&#x8BB0;&#x5F55;</td>
</tr>
<tr>
<td>execSQL(String sql)</td>
<td>&#x6267;&#x884C;&#x4E00;&#x6761;SQL&#x8BED;&#x53E5;</td>
</tr>
<tr>
<td>close()</td>
<td>&#x5173;&#x95ED;&#x6570;&#x636E;&#x5E93;</td>
</tr>
</tbody>
</table>
<h2 id="&#x6253;&#x5F00;&#x6216;&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;"><a href="#&#x6253;&#x5F00;&#x6216;&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;" class="headerlink" title="&#x6253;&#x5F00;&#x6216;&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;"></a>&#x6253;&#x5F00;&#x6216;&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;</h2><p>&#x5728;Android &#x4E2D;&#x4F7F;&#x7528;SQLiteDatabase&#x7684;&#x9759;&#x6001;&#x65B9;&#x6CD5;<code>openOrCreateDatabase(String  path,SQLiteDatabae.CursorFactory  factory)</code>&#x6253;&#x5F00;&#x6216;&#x8005;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#x3002;&#x5B83;&#x4F1A;&#x81EA;&#x52A8;&#x53BB;&#x68C0;&#x6D4B;&#x662F;&#x5426;&#x5B58;&#x5728;&#x8FD9;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x5982;&#x679C;&#x5B58;&#x5728;&#x5219;&#x6253;&#x5F00;&#xFF0C;&#x4E0D;&#x5B58;&#x5728;&#x5219;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#xFF1B;&#x521B;&#x5EFA;&#x6210;&#x529F;&#x5219;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;SQLiteDatabase&#x5BF9;&#x8C61;&#xFF0C;&#x5426;&#x5219;&#x629B;&#x51FA;&#x5F02;&#x5E38;FileNotFoundException&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x662F;&#x521B;&#x5EFA;&#x540D;&#x4E3A;&#x201C;stu.db&#x201D;&#x6570;&#x636E;&#x5E93;&#x7684;&#x4EE3;&#x7801;&#xFF1A;<br><code>openOrCreateDatabase(String  path,SQLiteDatabae.CursorFactory  factory)</code><br>&#x53C2;&#x6570;1  &#x6570;&#x636E;&#x5E93;&#x521B;&#x5EFA;&#x7684;&#x8DEF;&#x5F84;<br>&#x53C2;&#x6570;2  &#x4E00;&#x822C;&#x8BBE;&#x7F6E;&#x4E3A;null&#x5C31;&#x53EF;&#x4EE5;&#x4E86;<br></p><figure class="highlight ebnf"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">db</span>=SQLiteDatabase.openOrCreateDatabase(<span class="string">&quot;/data/data/com.lingdududu.db/databases/stu.db&quot;</span>,null);</span><br></pre></td></tr></tbody></table></figure><p></p>
<h2 id="&#x521B;&#x5EFA;&#x8868;"><a href="#&#x521B;&#x5EFA;&#x8868;" class="headerlink" title="&#x521B;&#x5EFA;&#x8868;"></a>&#x521B;&#x5EFA;&#x8868;</h2><p>&#x521B;&#x5EFA;&#x4E86;&#x4E00;&#x5F20;&#x7528;&#x6237;&#x8868;&#xFF0C;&#x5C5E;&#x6027;&#x5217;&#x4E3A;&#xFF1A;id&#xFF08;&#x4E3B;&#x952E;&#x5E76;&#x4E14;&#x81EA;&#x52A8;&#x589E;&#x52A0;&#xFF09;&#x3001;sname&#xFF08;&#x5B66;&#x751F;&#x59D3;&#x540D;&#xFF09;&#x3001;snumber&#xFF08;&#x5B66;&#x53F7;&#xFF09;<br></p><figure class="highlight cpp"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">createTable</span><span class="params">(SQLiteDatabase db)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line">	<span class="comment">// &#x521B;&#x5EFA;&#x8868;SQL&#x8BED;&#x53E5;</span></span><br><span class="line">	String stu_table=<span class="string">&quot;CREATE TABLE IF NOT EXISTS usertable(_id integer primary key autoincrement,sname text,snumber text)&quot;</span>;</span><br><span class="line">	<span class="comment">// &#x6267;&#x884C;SQL&#x8BED;&#x53E5;</span></span><br><span class="line">	db.execSQL(stu_table);</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p></p>
<h2 id="&#x5224;&#x65AD;&#x6570;&#x636E;&#x8868;&#x662F;&#x5426;&#x5B58;&#x5728;"><a href="#&#x5224;&#x65AD;&#x6570;&#x636E;&#x8868;&#x662F;&#x5426;&#x5B58;&#x5728;" class="headerlink" title="&#x5224;&#x65AD;&#x6570;&#x636E;&#x8868;&#x662F;&#x5426;&#x5B58;&#x5728;"></a>&#x5224;&#x65AD;&#x6570;&#x636E;&#x8868;&#x662F;&#x5426;&#x5B58;&#x5728;</h2><p>sqlite_master&#x8FD9;&#x4E2A;&#x8868;&#x662F;&#x7CFB;&#x7EDF;&#x7684;&#x8868;&#xFF0C;sqlitedatabase&#x4F1A;&#x4E3A;&#x6BCF;&#x4E00;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x8FD9;&#x6837;&#x7684;&#x8868;&#xFF0C;&#x76EE;&#x7684;&#x662F;&#x7528;&#x6765;&#x8BB0;&#x5F55;&#x7528;&#x6237;&#x81EA;&#x5DF1;&#x521B;&#x5EFA;&#x7684;&#x8868;&#x7684;&#x7D22;&#x5F15;&#x3002;&#x5982;&#x679C;&#x7528;&#x6237;&#x8FDB;&#x884C;&#x4E86;&#x8868;&#x7684;&#x589E;&#x5220;&#x6539;&#x67E5;&#x64CD;&#x4F5C;&#xFF0C;&#x8FD9;&#x4E2A;&#x8868;&#x90FD;&#x4F1A;&#x76F8;&#x5E94;&#x7684;&#x8FDB;&#x884C;&#x7D22;&#x5F15;&#x7684;&#x6539;&#x52A8;&#x3002;&#x901A;&#x8FC7;&#x67E5;&#x8BE2;sqlite_master&#xFF0C;&#x5224;&#x65AD;&#x8868;&#x662F;&#x5426;&#x5B58;&#x5728;&#x3002;<br></p><figure class="highlight processing"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="built_in">boolean</span> isTableExist()</span><br><span class="line">{</span><br><span class="line">	<span class="keyword">String</span> sql = <span class="string">&quot;select count(*) as c from sqlite_master where type =&apos;table&apos; and name = &apos;tableName&apos;&quot;</span>;</span><br><span class="line">	 Cursor <span class="built_in">cursor</span> = db.rawQuery(sql, <span class="keyword">null</span>);</span><br><span class="line">     <span class="keyword">if</span>(<span class="built_in">cursor</span>.moveToNext())</span><br><span class="line">	{</span><br><span class="line">		<span class="built_in">int</span> count = <span class="built_in">cursor</span>.getInt(<span class="number">0</span>);</span><br><span class="line">		<span class="keyword">if</span>(count&gt;<span class="number">0</span>)</span><br><span class="line">			retutrn <span class="keyword">true</span>;</span><br><span class="line">	}</span><br><span class="line">	<span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p></p>
<h2 id="&#x6570;&#x636E;&#x8868;&#x5220;&#x9664;"><a href="#&#x6570;&#x636E;&#x8868;&#x5220;&#x9664;" class="headerlink" title="&#x6570;&#x636E;&#x8868;&#x5220;&#x9664;"></a>&#x6570;&#x636E;&#x8868;&#x5220;&#x9664;</h2><figure class="highlight cpp"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">drop</span><span class="params">(SQLiteDatabase db)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line">	<span class="comment">// &#x5220;&#x9664;&#x8868;&#x7684;SQL&#x8BED;&#x53E5;</span></span><br><span class="line">	String sql =<span class="string">&quot;DROP TABLE IF EXISTS stu_table&quot;</span>;   </span><br><span class="line">	<span class="comment">// &#x6267;&#x884C;SQL</span></span><br><span class="line">	db.execSQL(sql);   </span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<h2 id="&#x6570;&#x636E;&#x603B;&#x8BB0;&#x5F55;&#x6570;"><a href="#&#x6570;&#x636E;&#x603B;&#x8BB0;&#x5F55;&#x6570;" class="headerlink" title="&#x6570;&#x636E;&#x603B;&#x8BB0;&#x5F55;&#x6570;"></a>&#x6570;&#x636E;&#x603B;&#x8BB0;&#x5F55;&#x6570;</h2><figure class="highlight processing"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">long</span> allCaseNum( ){</span><br><span class="line">	<span class="keyword">long</span> count = <span class="number">0</span>;</span><br><span class="line">	<span class="comment">// &#x67E5;&#x8BE2;&#x8BB0;&#x5F55;&#x6570;&#x8BED;&#x53E5;</span></span><br><span class="line">    <span class="keyword">String</span> sql = <span class="string">&quot;select count(*) from tableName&quot;</span>;</span><br><span class="line">	Cursor <span class="built_in">cursor</span> = db.rawQuery(sql, <span class="keyword">null</span>);  </span><br><span class="line">	<span class="keyword">if</span>(<span class="built_in">cursor</span> != <span class="keyword">null</span>)</span><br><span class="line">	{</span><br><span class="line">		<span class="built_in">cursor</span>.moveToFirst();</span><br><span class="line">    	<span class="keyword">long</span> count = <span class="built_in">cursor</span>.getLong(<span class="number">0</span>);  </span><br><span class="line">    	<span class="built_in">cursor</span>.close();</span><br><span class="line">	}  </span><br><span class="line">    <span class="keyword">return</span> count;  </span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<h2 id="&#x63D2;&#x5165;&#x6570;&#x636E;"><a href="#&#x63D2;&#x5165;&#x6570;&#x636E;" class="headerlink" title="&#x63D2;&#x5165;&#x6570;&#x636E;"></a>&#x63D2;&#x5165;&#x6570;&#x636E;</h2><p>&#x4E24;&#x79CD;&#x65B9;&#x5F0F;&#x63D2;&#x5165;&#x6570;&#x636E;</p>
<ul>
<li><p><code>SQLiteDatabase&#x7684;insert(String table,String nullColumnHack,ContentValues  values)&#x65B9;&#x6CD5;</code><br>&#x53C2;&#x6570;1  &#x8868;&#x540D;&#x79F0;&#xFF0C;<br>&#x53C2;&#x6570;2  &#x7A7A;&#x5217;&#x7684;&#x9ED8;&#x8BA4;&#x503C;<br>&#x53C2;&#x6570;3  ContentValues&#x7C7B;&#x578B;&#x7684;&#x4E00;&#x4E2A;&#x5C01;&#x88C5;&#x4E86;&#x5217;&#x540D;&#x79F0;&#x548C;&#x5217;&#x503C;&#x7684;Map&#xFF1B;</p>
  <figure class="highlight arduino"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> insert(SQLiteDatabase db)</span><br><span class="line">{   </span><br><span class="line">   	<span class="comment">// &#x5B9E;&#x4F8B;&#x5316;&#x5E38;&#x91CF;&#x503C;   </span></span><br><span class="line">   	ContentValues cValue = <span class="keyword">new</span> ContentValues();   </span><br><span class="line">   	<span class="comment">// &#x6DFB;&#x52A0;&#x7528;&#x6237;&#x540D;   </span></span><br><span class="line">   	cValue.<span class="built_in">put</span>(<span class="string">&quot;sname&quot;</span>,<span class="string">&quot;xiaoming&quot;</span>);   </span><br><span class="line">   	<span class="comment">// &#x6DFB;&#x52A0;&#x5BC6;&#x7801;   </span></span><br><span class="line">   	cValue.<span class="built_in">put</span>(<span class="string">&quot;snumber&quot;</span>,<span class="string">&quot;01005&quot;</span>);   </span><br><span class="line">   	<span class="comment">// &#x8C03;&#x7528;insert()&#x65B9;&#x6CD5;&#x63D2;&#x5165;&#x6570;&#x636E;   </span></span><br><span class="line">   	db.insert(<span class="string">&quot;stu_table&quot;</span>,null,cValue);   </span><br><span class="line">   }</span><br></pre></td></tr></tbody></table></figure>
</li>
<li><p>&#x7F16;&#x5199;&#x63D2;&#x5165;&#x6570;&#x636E;&#x7684;SQL&#x8BED;&#x53E5;&#xFF0C;&#x76F4;&#x63A5;&#x8C03;&#x7528;SQLiteDatabase&#x7684;execSQL()&#x65B9;&#x6CD5;&#x6765;&#x6267;&#x884C;</p>
  <figure class="highlight cpp"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">insert</span><span class="params">(SQLiteDatabase db)</span></span></span><br><span class="line"><span class="function"></span>{   </span><br><span class="line">   	<span class="comment">//&#x63D2;&#x5165;&#x6570;&#x636E;SQL&#x8BED;&#x53E5;</span></span><br><span class="line">   	String stu_sql=<span class="string">&quot;insert into stu_table(sname,snumber) values(&apos;xiaoming&apos;,&apos;01005&apos;)&quot;</span>; </span><br><span class="line">   	<span class="comment">//&#x6267;&#x884C;SQL&#x8BED;&#x53E5;</span></span><br><span class="line">   	db.execSQL(sql);</span><br><span class="line">   }</span><br></pre></td></tr></tbody></table></figure>
</li>
</ul>
<h2 id="&#x5220;&#x9664;&#x6570;&#x636E;"><a href="#&#x5220;&#x9664;&#x6570;&#x636E;" class="headerlink" title="&#x5220;&#x9664;&#x6570;&#x636E;"></a>&#x5220;&#x9664;&#x6570;&#x636E;</h2><p>&#x4E24;&#x79CD;&#x65B9;&#x5F0F;</p>
<ul>
<li><p>&#x8C03;&#x7528;<code>SQLiteDatabase&#x7684;delete(String table,String whereClause,String[]  whereArgs)</code>&#x65B9;&#x6CD5;<br>&#x53C2;&#x6570;1  &#x8868;&#x540D;&#x79F0;<br>&#x53C2;&#x6570;2  &#x5220;&#x9664;&#x6761;&#x4EF6;<br>&#x53C2;&#x6570;3  &#x5220;&#x9664;&#x6761;&#x4EF6;&#x503C;&#x6570;&#x7EC4;</p>
  <figure class="highlight arduino"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="keyword">delete</span>(SQLiteDatabase db) </span><br><span class="line">{   </span><br><span class="line">   	<span class="comment">// &#x5220;&#x9664;&#x6761;&#x4EF6;</span></span><br><span class="line">   	<span class="keyword">String</span> whereClause = <span class="string">&quot;id=?&quot;</span>;</span><br><span class="line">   	<span class="comment">// &#x5220;&#x9664;&#x6761;&#x4EF6;&#x53C2;&#x6570;</span></span><br><span class="line">   	<span class="keyword">String</span>[] whereArgs = {<span class="keyword">String</span>.valueOf(<span class="number">2</span>)};</span><br><span class="line">   	<span class="comment">// &#x6267;&#x884C;&#x5220;&#x9664;</span></span><br><span class="line">   	db.<span class="keyword">delete</span>(<span class="string">&quot;stu_table&quot;</span>,whereClause,whereArgs); </span><br><span class="line">   }</span><br></pre></td></tr></tbody></table></figure>
</li>
<li><p>&#x7F16;&#x5199;&#x5220;&#x9664;SQL&#x8BED;&#x53E5;&#xFF0C;&#x8C03;&#x7528;SQLiteDatabase&#x7684;execSQL()&#x65B9;&#x6CD5;&#x6765;&#x6267;&#x884C;&#x5220;&#x9664;</p>
  <figure class="highlight arduino"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="keyword">delete</span>(SQLiteDatabase db) </span><br><span class="line">{   </span><br><span class="line">   	<span class="comment">// &#x5220;&#x9664;SQL&#x8BED;&#x53E5;</span></span><br><span class="line">   	<span class="keyword">String</span> sql = <span class="string">&quot;delete from stu_table where _id = 6&quot;</span>;</span><br><span class="line">   	<span class="comment">// &#x6267;&#x884C;SQL&#x8BED;&#x53E5;</span></span><br><span class="line">   	db.execSQL(sql);</span><br><span class="line">   }</span><br></pre></td></tr></tbody></table></figure>
</li>
</ul>
<h2 id="&#x4FEE;&#x6539;&#x6570;&#x636E;"><a href="#&#x4FEE;&#x6539;&#x6570;&#x636E;" class="headerlink" title="&#x4FEE;&#x6539;&#x6570;&#x636E;"></a>&#x4FEE;&#x6539;&#x6570;&#x636E;</h2><p>&#x4E24;&#x79CD;&#x65B9;&#x5F0F;</p>
<ul>
<li><p>&#x8C03;&#x7528;<code>SQLiteDatabase&#x7684;update(String table,ContentValues values,String  whereClause, String[]  whereArgs)</code>&#x65B9;&#x6CD5;<br>&#x53C2;&#x6570;1  &#x8868;&#x540D;&#x79F0;<br>&#x53C2;&#x6570;2  &#x8DDF;&#x884C;&#x5217;ContentValues&#x7C7B;&#x578B;&#x7684;&#x952E;&#x503C;&#x5BF9;Key-Value<br>&#x53C2;&#x6570;3  &#x66F4;&#x65B0;&#x6761;&#x4EF6;&#xFF08;where&#x5B57;&#x53E5;&#xFF09;<br>&#x53C2;&#x6570;4  &#x66F4;&#x65B0;&#x6761;&#x4EF6;&#x6570;&#x7EC4;</p>
  <figure class="highlight arduino"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> update(SQLiteDatabase db) </span><br><span class="line">{   </span><br><span class="line">   	<span class="comment">// &#x5B9E;&#x4F8B;&#x5316;&#x5185;&#x5BB9;&#x503C; </span></span><br><span class="line">	ContentValues values = <span class="keyword">new</span> ContentValues();   </span><br><span class="line">   	<span class="comment">// &#x5728;values&#x4E2D;&#x6DFB;&#x52A0;&#x5185;&#x5BB9;   </span></span><br><span class="line">   	values.<span class="built_in">put</span>(<span class="string">&quot;snumber&quot;</span>,<span class="string">&quot;101003&quot;</span>);   </span><br><span class="line">   	<span class="comment">// &#x4FEE;&#x6539;&#x6761;&#x4EF6;   </span></span><br><span class="line">   	<span class="keyword">String</span> whereClause = <span class="string">&quot;id=?&quot;</span>;   </span><br><span class="line">   	<span class="comment">// &#x4FEE;&#x6539;&#x6DFB;&#x52A0;&#x53C2;&#x6570;   </span></span><br><span class="line">   	<span class="keyword">String</span>[] whereArgs={<span class="keyword">String</span>.valuesOf(<span class="number">1</span>)};   </span><br><span class="line">   	<span class="comment">// &#x4FEE;&#x6539;   </span></span><br><span class="line">   	db.update(<span class="string">&quot;usertable&quot;</span>,values,whereClause,whereArgs);   </span><br><span class="line">   }</span><br></pre></td></tr></tbody></table></figure>
</li>
<li><p>&#x7F16;&#x5199;&#x66F4;&#x65B0;&#x7684;SQL&#x8BED;&#x53E5;&#xFF0C;&#x8C03;&#x7528;SQLiteDatabase&#x7684;execSQL&#x6267;&#x884C;&#x66F4;&#x65B0;</p>
 <figure class="highlight cpp"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">update</span><span class="params">(SQLiteDatabase db)</span></span></span><br><span class="line"><span class="function"></span>{   </span><br><span class="line">   	<span class="comment">// &#x4FEE;&#x6539;SQL&#x8BED;&#x53E5;</span></span><br><span class="line">   	String sql = <span class="string">&quot;update stu_table set snumber = 654321 where id = 1&quot;</span>;</span><br><span class="line">   	<span class="comment">// &#x6267;&#x884C;SQL</span></span><br><span class="line">   	db.execSQL(sql); </span><br><span class="line">   }</span><br></pre></td></tr></tbody></table></figure>
</li>
</ul>
<h2 id="&#x67E5;&#x8BE2;&#x6570;&#x636E;"><a href="#&#x67E5;&#x8BE2;&#x6570;&#x636E;" class="headerlink" title="&#x67E5;&#x8BE2;&#x6570;&#x636E;"></a>&#x67E5;&#x8BE2;&#x6570;&#x636E;</h2><p>&#x5728;Android&#x4E2D;&#x67E5;&#x8BE2;&#x6570;&#x636E;&#x662F;&#x901A;&#x8FC7;Cursor&#x7C7B;&#x6765;&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x5F53;&#x6211;&#x4EEC;&#x4F7F;&#x7528;<code>SQLiteDatabase.query()</code>&#x65B9;&#x6CD5;&#x65F6;&#xFF0C;&#x4F1A;&#x5F97;&#x5230;&#x4E00;&#x4E2A;Cursor&#x5BF9;&#x8C61;&#xFF0C;Cursor&#x6307;&#x5411;&#x7684;&#x5C31;&#x662F;&#x6BCF;&#x4E00;&#x6761;&#x6570;&#x636E;&#x3002;&#x5B83;&#x63D0;&#x4F9B;&#x4E86;&#x5F88;&#x591A;&#x6709;&#x5173;&#x67E5;&#x8BE2;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x5177;&#x4F53;&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;<br><code>public  Cursor query(String table,String[] columns,String selection,String[]  selectionArgs,String groupBy,String having,String orderBy,String limit);</code></p>
<p>&#x5404;&#x4E2A;&#x53C2;&#x6570;&#x7684;&#x610F;&#x4E49;&#x8BF4;&#x660E;&#xFF1A;<br>&#x53C2;&#x6570;table:&#x8868;&#x540D;&#x79F0;<br>&#x53C2;&#x6570;columns:&#x5217;&#x540D;&#x79F0;&#x6570;&#x7EC4;<br>&#x53C2;&#x6570;selection:&#x6761;&#x4EF6;&#x5B57;&#x53E5;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;where<br>&#x53C2;&#x6570;selectionArgs:&#x6761;&#x4EF6;&#x5B57;&#x53E5;&#xFF0C;&#x53C2;&#x6570;&#x6570;&#x7EC4;<br>&#x53C2;&#x6570;groupBy:&#x5206;&#x7EC4;&#x5217;<br>&#x53C2;&#x6570;having:&#x5206;&#x7EC4;&#x6761;&#x4EF6;<br>&#x53C2;&#x6570;orderBy:&#x6392;&#x5E8F;&#x5217;<br>&#x53C2;&#x6570;limit:&#x5206;&#x9875;&#x67E5;&#x8BE2;&#x9650;&#x5236;<br>&#x53C2;&#x6570;Cursor:&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;&#x7ED3;&#x679C;&#x96C6;ResultSet</p>
<p>Cursor&#x662F;&#x4E00;&#x4E2A;&#x6E38;&#x6807;&#x63A5;&#x53E3;&#xFF0C;&#x63D0;&#x4F9B;&#x4E86;&#x904D;&#x5386;&#x67E5;&#x8BE2;&#x7ED3;&#x679C;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x5982;&#x79FB;&#x52A8;&#x6307;&#x9488;&#x65B9;&#x6CD5;move()&#xFF0C;&#x83B7;&#x5F97;&#x5217;&#x503C;&#x65B9;&#x6CD5;getString()&#x7B49;.</p>
<p>Cursor&#x6E38;&#x6807;&#x5E38;&#x7528;&#x65B9;&#x6CD5;</p>
<table>
<thead>
<tr>
<th>&#x65B9;&#x6CD5;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td>getCount()</td>
<td>&#x83B7;&#x5F97;&#x603B;&#x7684;&#x6570;&#x636E;&#x9879;&#x6570;</td>
</tr>
<tr>
<td>isFirst()</td>
<td>&#x5224;&#x65AD;&#x662F;&#x5426;&#x7B2C;&#x4E00;&#x6761;&#x8BB0;&#x5F55;</td>
</tr>
<tr>
<td>isLast()</td>
<td>&#x5224;&#x65AD;&#x662F;&#x5426;&#x6700;&#x540E;&#x4E00;&#x6761;&#x8BB0;&#x5F55;</td>
</tr>
<tr>
<td>moveToFirst()</td>
<td>&#x79FB;&#x52A8;&#x5230;&#x7B2C;&#x4E00;&#x6761;&#x8BB0;&#x5F55;</td>
</tr>
<tr>
<td>moveToLast()</td>
<td>&#x79FB;&#x52A8;&#x5230;&#x6700;&#x540E;&#x4E00;&#x6761;&#x8BB0;&#x5F55;</td>
</tr>
<tr>
<td>move(int offset)</td>
<td>&#x79FB;&#x52A8;&#x5230;&#x6307;&#x5B9A;&#x8BB0;&#x5F55;</td>
</tr>
<tr>
<td>moveToNext()</td>
<td>&#x79FB;&#x52A8;&#x5230;&#x4E0B;&#x4E00;&#x6761;&#x8BB0;&#x5F55;</td>
</tr>
<tr>
<td>moveToPrevious()</td>
<td>&#x79FB;&#x52A8;&#x5230;&#x4E0A;&#x4E00;&#x6761;&#x8BB0;&#x5F55;</td>
</tr>
<tr>
<td>getColumnIndexOrThrow(String  columnName)</td>
<td>&#x6839;&#x636E;&#x5217;&#x540D;&#x79F0;&#x83B7;&#x5F97;&#x5217;&#x7D22;&#x5F15;</td>
</tr>
<tr>
<td>getInt(int columnIndex)</td>
<td>&#x83B7;&#x5F97;&#x6307;&#x5B9A;&#x5217;&#x7D22;&#x5F15;&#x7684;int&#x7C7B;&#x578B;&#x503C;</td>
</tr>
<tr>
<td>getString(int columnIndex)</td>
<td>&#x83B7;&#x5F97;&#x6307;&#x5B9A;&#x5217;&#x7F29;&#x5F71;&#x7684;String&#x7C7B;&#x578B;&#x503C;</td>
</tr>
</tbody>
</table>
<p>&#x793A;&#x4F8B;&#xFF1A;&#x67E5;&#x8BE2;&#x6570;&#x636E;<br></p><figure class="highlight processing"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> query(SQLiteDatabase db) </span><br><span class="line">{   </span><br><span class="line">	<span class="comment">// &#x67E5;&#x8BE2;&#x83B7;&#x5F97;&#x6E38;&#x6807;   </span></span><br><span class="line">	Cursor <span class="built_in">cursor</span> = db.query (<span class="string">&quot;usertable&quot;</span>,<span class="keyword">null</span>,<span class="keyword">null</span>,<span class="keyword">null</span>,<span class="keyword">null</span>,<span class="keyword">null</span>,<span class="keyword">null</span>);   </span><br><span class="line">	<span class="comment">// &#x5224;&#x65AD;&#x6E38;&#x6807;&#x662F;&#x5426;&#x4E3A;&#x7A7A;   </span></span><br><span class="line">	<span class="keyword">if</span>(<span class="built_in">cursor</span>.moveToFirst() </span><br><span class="line">	{   </span><br><span class="line">		<span class="comment">// &#x904D;&#x5386;&#x6E38;&#x6807;   </span></span><br><span class="line">		<span class="keyword">for</span>(<span class="built_in">int</span> i=<span class="number">0</span>;i&lt;<span class="built_in">cursor</span>.getCount();i++)</span><br><span class="line">		{   </span><br><span class="line">			<span class="built_in">cursor</span>.move(i);   </span><br><span class="line">			<span class="comment">// &#x83B7;&#x5F97;ID   </span></span><br><span class="line">			<span class="built_in">int</span> id = <span class="built_in">cursor</span>.getInt(<span class="number">0</span>);   </span><br><span class="line">			<span class="comment">// &#x83B7;&#x5F97;&#x7528;&#x6237;&#x540D;   </span></span><br><span class="line">			<span class="keyword">String</span> username=<span class="built_in">cursor</span>.getString(<span class="number">1</span>);   </span><br><span class="line">			<span class="comment">// &#x83B7;&#x5F97;&#x5BC6;&#x7801;   </span></span><br><span class="line">			<span class="keyword">String</span> password=<span class="built_in">cursor</span>.getString(<span class="number">2</span>);   </span><br><span class="line">			<span class="comment">// &#x8F93;&#x51FA;&#x7528;&#x6237;&#x4FE1;&#x606F; </span></span><br><span class="line">			System.out.<span class="built_in">println</span>(id+<span class="string">&quot;:&quot;</span>+sname+<span class="string">&quot;:&quot;</span>+snumber);   </span><br><span class="line">		}   </span><br><span class="line">	}   </span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p></p>
<h1 id="SQLiteOpenHelper"><a href="#SQLiteOpenHelper" class="headerlink" title="SQLiteOpenHelper"></a>SQLiteOpenHelper</h1><p>&#x8BE5;&#x7C7B;&#x662F;SQLiteDatabase&#x4E00;&#x4E2A;&#x8F85;&#x52A9;&#x7C7B;&#x3002;&#x8FD9;&#x4E2A;&#x7C7B;&#x4E3B;&#x8981;&#x751F;&#x6210;&#x4E00; &#x4E2A;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x5E76;&#x5BF9;&#x6570;&#x636E;&#x5E93;&#x7684;&#x7248;&#x672C;&#x8FDB;&#x884C;&#x7BA1;&#x7406;&#x3002;<strong>&#x5728;&#x7279;&#x6B8A;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5373;&#x5F53;&#x6253;&#x5F00;&#x5916;&#x90E8;&#x6570;&#x636E;&#x5E93;&#x5982;<code>/sdcard/sqlite.db</code>&#xFF0C;&#x5219;&#x4E0D;&#x4F1A;&#x6267;&#x884C;&#x7BA1;&#x7406;&#xFF1B;&#x800C;&#x4E00;&#x822C;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5373;&#x6253;&#x5F00;<code>/data/data/package/databases/</code>&#x5E94;&#x7528;&#x91CC;&#x7684;&#x5185;&#x90E8;&#x6570;&#x636E;&#x5E93;&#x4F1A;&#x6267;&#x884C;&#x7BA1;&#x7406;</strong>&#x3002;&#x5F53;&#x5728;&#x7A0B;&#x5E8F;&#x5F53;&#x4E2D;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;&#x7C7B;&#x7684;&#x65B9;&#x6CD5;getWritableDatabase()&#x6216;&#x8005; getReadableDatabase()&#x65B9;&#x6CD5;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5982;&#x679C;&#x5F53;&#x65F6;&#x6CA1;&#x6709;&#x6570;&#x636E;&#xFF0C;&#x90A3;&#x4E48;Android&#x7CFB;&#x7EDF;&#x5C31;&#x4F1A;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#x3002; SQLiteOpenHelper &#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x6211;&#x4EEC;&#x901A;&#x5E38;&#x9700;&#x8981;&#x7EE7;&#x627F;&#x5B83;&#xFF0C;&#x5E76;&#x4E14;&#x5B9E;&#x73B0;&#x91CC;&#x9762;&#x7684;3&#x4E2A;&#x51FD;&#x6570;&#xFF1A;</p>
<ul>
<li><p>onCreate(SQLiteDatabase)<br>&#x5728;&#x6570;&#x636E;&#x5E93;&#x7B2C;&#x4E00;&#x6B21;&#x751F;&#x6210;&#x7684;&#x65F6;&#x5019;&#x4F1A;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x53EA;&#x6709;&#x5728;&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;&#x7684;&#x65F6;&#x5019;&#x624D;&#x4F1A;&#x8C03;&#x7528;&#xFF0C;&#x5F53;&#x7136;&#x4E5F;&#x6709;&#x4E00;&#x4E9B;&#x5176;&#x5B83;&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x4E00;&#x822C;&#x6211;&#x4EEC;&#x5728;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x91CC;&#x8FB9;&#x751F;&#x6210;&#x6570;&#x636E;&#x5E93;&#x8868;&#x3002;</p>
</li>
<li><p>onUpgrade(SQLiteDatabase&#xFF0C;int&#xFF0C;int)<br>&#x5F53;&#x6570;&#x636E;&#x5E93;&#x9700;&#x8981;&#x5347;&#x7EA7;&#x7684;&#x65F6;&#x5019;&#xFF0C;Android&#x7CFB;&#x7EDF;&#x4F1A;&#x4E3B;&#x52A8;&#x7684;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x3002;&#x4E00;&#x822C;&#x6211;&#x4EEC;&#x5728;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x91CC;&#x8FB9;&#x5220;&#x9664;&#x6570;&#x636E;&#x8868;&#xFF0C;&#x5E76;&#x5EFA;&#x7ACB;&#x65B0;&#x7684;&#x6570;&#x636E;&#x8868;&#xFF0C;&#x5F53;&#x7136;&#x662F;&#x5426;&#x8FD8;&#x9700;&#x8981;&#x505A;&#x5176;&#x4ED6;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x5B8C;&#x5168;&#x53D6;&#x51B3;&#x4E8E;&#x5E94;&#x7528;&#x7684;&#x9700;&#x6C42;&#x3002;</p>
</li>
<li><p>onOpen(SQLiteDatabase)<br>&#x8FD9;&#x662F;&#x5F53;&#x6253;&#x5F00;&#x6570;&#x636E;&#x5E93;&#x65F6;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF0C;&#x4E00;&#x822C;&#x5728;&#x7A0B;&#x5E8F;&#x4E2D;&#x4E0D;&#x662F;&#x5F88;&#x5E38;&#x4F7F;&#x7528;&#x3002;</p>
</li>
</ul>
<h2 id="SQLiteOpenHelper&#x64CD;&#x4F5C;&#x5185;&#x90E8;&#x6570;&#x636E;&#x5E93;"><a href="#SQLiteOpenHelper&#x64CD;&#x4F5C;&#x5185;&#x90E8;&#x6570;&#x636E;&#x5E93;" class="headerlink" title="SQLiteOpenHelper&#x64CD;&#x4F5C;&#x5185;&#x90E8;&#x6570;&#x636E;&#x5E93;"></a>SQLiteOpenHelper&#x64CD;&#x4F5C;&#x5185;&#x90E8;&#x6570;&#x636E;&#x5E93;</h2><p>&#x6570;&#x636E;&#x5E93;&#x5E2E;&#x52A9;&#x7C7B;SQLiteOpenHelper&#x64CD;&#x4F5C;&#x5185;&#x90E8;&#x6570;&#x636E;&#x5E93;&#x65F6;&#xFF0C;&#x5728;&#x5E94;&#x7528;&#x5B89;&#x88C5;&#x540E;&#x7B2C;&#x4E00;&#x6B21;&#x542F;&#x52A8;&#x65F6;<strong>&#x4F1A;&#x6267;&#x884C;onCreate&#x65B9;&#x6CD5;</strong>&#xFF0C;&#x5728;&#x6B64;&#x65B9;&#x6CD5;&#x4E2D;&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;&#x3002;<br></p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">DBUtils</span> <span class="keyword">extends</span> <span class="title">SQLiteOpenHelper</span> </span>{</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">protected</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">int</span>	DB_VERSION		= BuildConfig.dbVersion;</span><br><span class="line">	<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> String	SQLITE_MASTER		= <span class="string">&quot;sqlite_master &quot;</span>;</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">protected</span> SQLiteDatabase	mDatabase		= <span class="keyword">null</span>;</span><br><span class="line">	</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="title">DBUtils</span><span class="params">(Context context, String name, SQLiteDatabase.CursorFactory factory, <span class="keyword">int</span> version)</span> </span>{</span><br><span class="line">		<span class="keyword">super</span>(context, name, factory, version);</span><br><span class="line">		<span class="keyword">try</span> {</span><br><span class="line">			mDatabase = getWritableDatabase();</span><br><span class="line">		} <span class="keyword">catch</span> (Exception e) {</span><br><span class="line">			mDatabase = getReadableDatabase();</span><br><span class="line">		}</span><br><span class="line">	}</span><br><span class="line">	</span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onCreate</span><span class="params">(SQLiteDatabase db)</span> </span>{</span><br><span class="line">		<span class="keyword">if</span> (mDatabase == <span class="keyword">null</span>)</span><br><span class="line">			mDatabase = db;</span><br><span class="line">	}</span><br><span class="line">	</span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onUpgrade</span><span class="params">(SQLiteDatabase db, <span class="keyword">int</span> oldVersion, <span class="keyword">int</span> newVersion)</span> </span>{</span><br><span class="line">		mDatabase = db;</span><br><span class="line">	}</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p></p>
<h2 id="SQLiteOpenHelper&#x64CD;&#x4F5C;&#x5916;&#x90E8;&#x6570;&#x636E;&#x5E93;"><a href="#SQLiteOpenHelper&#x64CD;&#x4F5C;&#x5916;&#x90E8;&#x6570;&#x636E;&#x5E93;" class="headerlink" title="SQLiteOpenHelper&#x64CD;&#x4F5C;&#x5916;&#x90E8;&#x6570;&#x636E;&#x5E93;"></a>SQLiteOpenHelper&#x64CD;&#x4F5C;&#x5916;&#x90E8;&#x6570;&#x636E;&#x5E93;</h2><p>&#x6570;&#x636E;&#x5E93;&#x5E2E;&#x52A9;&#x7C7B;SQLiteOpenHelper&#x64CD;&#x4F5C;&#x5916;&#x90E8;&#x6570;&#x636E;&#x5E93;&#x65F6;&#xFF0C;&#x5728;&#x5E94;&#x7528;&#x5B89;&#x88C5;&#x540E;&#x7B2C;&#x4E00;&#x6B21;&#x542F;&#x52A8;&#x65F6;<strong>&#x4E0D;&#x4F1A;&#x6267;&#x884C;onCreate&#x65B9;&#x6CD5;</strong>&#x3002;</p>
<ul>
<li><p>&#x501F;&#x52A9;ContextWrapper&#x7C7B;&#x6253;&#x5F00;&#x5916;&#x90E8;&#x6570;&#x636E;&#x5E93;&#xFF0C;<strong>&#x6CE8;&#x610F;&#x6570;&#x636E;&#x5E93;&#x6587;&#x4EF6;&#x9700;&#x8981;&#x5224;&#x65AD;&#x662F;&#x5426;&#x5B58;&#x5728;&#xFF0C;&#x5426;&#x5219;&#x62A5;&#x9519;</strong></p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">DatabaseContext</span> <span class="keyword">extends</span> <span class="title">ContextWrapper</span> </span>{</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">private</span> String mDBPath = <span class="keyword">null</span>;</span><br><span class="line">	</span><br><span class="line">	<span class="function"><span class="keyword">private</span> <span class="title">DatabaseContext</span><span class="params">(Context base)</span> </span>{</span><br><span class="line">		<span class="keyword">super</span>(base);</span><br><span class="line">	}</span><br><span class="line">	</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="title">DatabaseContext</span><span class="params">(Context base, String dbPath)</span> </span>{</span><br><span class="line">		<span class="keyword">super</span>(base);</span><br><span class="line">		mDBPath = dbPath;</span><br><span class="line">	}</span><br><span class="line">	</span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> File <span class="title">getDatabasePath</span><span class="params">(String name)</span> </span>{</span><br><span class="line">		String dbPath = mDBPath + name;</span><br><span class="line">		<span class="keyword">if</span> (FileUtils.isFileExists(dbPath)) {</span><br><span class="line">			<span class="keyword">return</span> <span class="keyword">new</span> File(dbPath);</span><br><span class="line">		} <span class="keyword">else</span> {</span><br><span class="line">			<span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">		}</span><br><span class="line">	}</span><br><span class="line">	</span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> SQLiteDatabase <span class="title">openOrCreateDatabase</span><span class="params">(String name, <span class="keyword">int</span> mode, SQLiteDatabase.CursorFactory factory)</span> </span>{</span><br><span class="line">		<span class="keyword">int</span> flags = SQLiteDatabase.CREATE_IF_NECESSARY | SQLiteDatabase.NO_LOCALIZED_COLLATORS;</span><br><span class="line">		<span class="keyword">return</span> SQLiteDatabase.openDatabase(getDatabasePath(name).getAbsolutePath(), factory, flags, <span class="keyword">null</span>);</span><br><span class="line">	}</span><br><span class="line">	</span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> SQLiteDatabase <span class="title">openOrCreateDatabase</span><span class="params">(String name, <span class="keyword">int</span> mode, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler)</span> </span>{</span><br><span class="line">		<span class="keyword">int</span> flags = SQLiteDatabase.CREATE_IF_NECESSARY | SQLiteDatabase.NO_LOCALIZED_COLLATORS;</span><br><span class="line">		<span class="keyword">return</span> SQLiteDatabase.openDatabase(getDatabasePath(name).getAbsolutePath(), factory, flags, errorHandler);</span><br><span class="line">	}</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
</li>
<li><p>&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;&#x5E2E;&#x52A9;&#x7C7B;&#xFF0C;&#x5F00;&#x542F;&#x6570;&#x636E;&#x5E93;&#x64CD;&#x4F5C;</p>
<figure class="highlight cs"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">UtilDao</span></span><br><span class="line">{</span><br><span class="line">	<span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">initDao</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>	{</span><br><span class="line">		<span class="comment">// DB_PATH &#x6570;&#x636E;&#x5E93;&#x6587;&#x4EF6;&#x8DEF;&#x5F84;&#xFF0C;&#x5982;&#xFF1A;/sdcard/db/sqlite.db </span></span><br><span class="line">		DatabaseContext dbContext = <span class="keyword">new</span> DatabaseContext(mContext, DB_PATH);</span><br><span class="line">		<span class="comment">// &#x7136;&#x540E;&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;&#x5E2E;&#x52A9;&#x7C7B;&#xFF0C;&#x540E;&#x9762;&#x7684;&#x64CD;&#x4F5C;&#x4E0E;&#x5185;&#x90E8;&#x6570;&#x636E;&#x5E93;&#x4E00;&#x81F4;&#x3002;&#x53C2;&#x6570;Context&#x3001;&#x6570;&#x636E;&#x8868;&#x540D;&#x3001;&#x6570;&#x636E;&#x5E93;&#x7248;&#x672C;&#x53F7;&#x7B49;</span></span><br><span class="line">		DBUtils dbUtils = <span class="keyword">new</span> DBUtils(mContext, tableName, <span class="literal">null</span>, dbVersion);</span><br><span class="line">	}</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
</li>
</ul>
<h1 id="Android&#x5E38;&#x7528;SQLite&#x547D;&#x4EE4;"><a href="#Android&#x5E38;&#x7528;SQLite&#x547D;&#x4EE4;" class="headerlink" title="Android&#x5E38;&#x7528;SQLite&#x547D;&#x4EE4;"></a>Android&#x5E38;&#x7528;SQLite&#x547D;&#x4EE4;</h1><ul>
<li><p>&#x6253;&#x5F00;&#x6570;&#x636E;&#x5E93; </p>
  <figure class="highlight avrasm"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&gt; sqlite3 sql<span class="meta">.db</span></span><br></pre></td></tr></tbody></table></figure>
</li>
<li><p>&#x67E5;&#x770B;</p>
  <figure class="highlight stylus"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">sqlite&gt; <span class="selector-class">.database</span> <span class="comment">// &#x663E;&#x793A;&#x6570;&#x636E;&#x5E93;&#x4FE1;&#x606F;</span></span><br><span class="line">sqlite&gt; <span class="selector-class">.tables</span> <span class="comment">// &#x663E;&#x793A;&#x8868;&#x540D;</span></span><br><span class="line">sqlite&gt; <span class="selector-class">.schema</span> <span class="comment">// &#x547D;&#x4EE4;&#x53EF;&#x4EE5;&#x67E5;&#x770B;&#x521B;&#x5EFA;&#x6570;&#x636E;&#x8868;&#x65F6;&#x7684;SQL&#x547D;&#x4EE4;</span></span><br><span class="line">sqlite&gt; <span class="selector-class">.schema</span> table_name <span class="comment">// &#x67E5;&#x770B;&#x521B;&#x5EFA;&#x8868;table_name&#x65F6;&#x7684;SQL&#x7684;&#x547D;&#x4EE4;</span></span><br></pre></td></tr></tbody></table></figure>
</li>
<li><p>&#x63D2;&#x5165;&#x8BB0;&#x5F55;</p>
  <figure class="highlight n1ql"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> table_name <span class="keyword">values</span> (field1, field2, field3...);</span><br></pre></td></tr></tbody></table></figure>
</li>
<li><p>&#x5220;&#x9664;</p>
  <figure class="highlight sql"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> <span class="keyword">if</span> <span class="keyword">exists</span> table_name;    // &#x5220;&#x9664;&#x8868;</span><br></pre></td></tr></tbody></table></figure>
</li>
<li><p>&#x4FEE;&#x6539;</p>
  <figure class="highlight routeros"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">update table <span class="builtin-name">set</span> <span class="attribute">field1</span>=<span class="string">&apos;xxxxx&apos;</span> where <span class="attribute">option1</span>=<span class="string">&apos;&apos;</span>;</span><br></pre></td></tr></tbody></table></figure>
</li>
<li><p>&#x67E5;&#x8BE2;</p>
  <figure class="highlight cs"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> * <span class="keyword">from</span> table_name;	<span class="comment">// &#x67E5;&#x770B;table_name&#x8868;&#x4E2D;&#x6240;&#x6709;&#x8BB0;&#x5F55;</span></span><br><span class="line"><span class="keyword">select</span> * <span class="keyword">from</span> table_name <span class="keyword">where</span> field1=<span class="string">&apos;xxxxx&apos;</span>;  <span class="comment">// &#x67E5;&#x8BE2;&#x7B26;&#x5408;&#x6307;&#x5B9A;&#x6761;&#x4EF6;&#x7684;&#x8BB0;&#x5F55;</span></span><br></pre></td></tr></tbody></table></figure>
</li>
</ul>
<script>
        document.querySelectorAll('.github-emoji')
          .forEach(el => {
            if (!el.dataset.src) { return; }
            const img = document.createElement('img');
            img.style = 'display:none !important;';
            img.src = el.dataset.src;
            img.addEventListener('error', () => {
              img.remove();
              el.style.color = 'inherit';
              el.style.backgroundImage = 'none';
              el.style.background = 'none';
            });
            img.addEventListener('load', () => {
              img.remove();
            });
            document.body.appendChild(img);
          });
      </script>
      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>谢谢老板，请尽情用红包来蹂躏我吧！！！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/uploads/wechatpay.jpg" alt="Tiimor 微信打赏">
        <p>微信打赏</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/uploads/alipay.jpg" alt="Tiimor 支付宝打赏">
        <p>支付宝打赏</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <!-- modify by zhangwei -->
            <!-- 文章底部标签图标 -->
            <a href="/tags/Android/" rel="tag"><i class="menu-item-icon fa fa-tag fa-fw"></i>Android</a>
          
            <!-- modify by zhangwei -->
            <!-- 文章底部标签图标 -->
            <a href="/tags/SQLite/" rel="tag"><i class="menu-item-icon fa fa-tag fa-fw"></i>SQLite</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/Android青铜篇-selector/" rel="next" title="Android青铜篇-selector">
                <i class="fa fa-chevron-left"></i> Android青铜篇-selector
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/Android铂金篇-SQLite全文检索/" rel="prev" title="Android铂金篇-SQLite全文检索">
                Android铂金篇-SQLite全文检索 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      
        <div id="gitment-container"></div>
      
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/uploads/avatar.jpg" alt="Tiimor">
            
              <p class="site-author-name" itemprop="name">Tiimor</p>
              <p class="site-description motion-element" itemprop="description">安静地做一只攻城狮。</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">41</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">56</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/VeiZhang" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://www.weibo.com/tiimor" target="_blank" title="微博">
                      
                        <i class="fa fa-fw fa-weibo"></i>微博</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://juejin.im/user/589972d0570c3500624fd791" target="_blank" title="掘金">
                      
                        <i class="fa fa-fw fa-anchor"></i>掘金</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://www.jianshu.com/u/93b886580243" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-book"></i>简书</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://wpa.qq.com/msgrd?v=3&uin=690393541&site=qq&menu=yes" target="_blank" title="QQ">
                      
                        <i class="fa fa-fw fa-qq"></i>QQ</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:tiimor@qq.com" target="_blank" title="邮箱">
                      
                        <i class="fa fa-fw fa-envelope"></i>邮箱</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#SQLite介绍"><span class="nav-number">1.</span> <span class="nav-text">SQLite介绍</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SQLite特点"><span class="nav-number">2.</span> <span class="nav-text">SQLite特点</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SQLite数据类型"><span class="nav-number">3.</span> <span class="nav-text">SQLite数据类型</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SQLiteDatabase的介绍"><span class="nav-number">4.</span> <span class="nav-text">SQLiteDatabase的介绍</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#打开或创建数据库"><span class="nav-number">4.1.</span> <span class="nav-text">打开或创建数据库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建表"><span class="nav-number">4.2.</span> <span class="nav-text">创建表</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#判断数据表是否存在"><span class="nav-number">4.3.</span> <span class="nav-text">判断数据表是否存在</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#数据表删除"><span class="nav-number">4.4.</span> <span class="nav-text">数据表删除</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#数据总记录数"><span class="nav-number">4.5.</span> <span class="nav-text">数据总记录数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#插入数据"><span class="nav-number">4.6.</span> <span class="nav-text">插入数据</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#删除数据"><span class="nav-number">4.7.</span> <span class="nav-text">删除数据</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#修改数据"><span class="nav-number">4.8.</span> <span class="nav-text">修改数据</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查询数据"><span class="nav-number">4.9.</span> <span class="nav-text">查询数据</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SQLiteOpenHelper"><span class="nav-number">5.</span> <span class="nav-text">SQLiteOpenHelper</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#SQLiteOpenHelper操作内部数据库"><span class="nav-number">5.1.</span> <span class="nav-text">SQLiteOpenHelper操作内部数据库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#SQLiteOpenHelper操作外部数据库"><span class="nav-number">5.2.</span> <span class="nav-text">SQLiteOpenHelper操作外部数据库</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Android常用SQLite命令"><span class="nav-number">6.</span> <span class="nav-text">Android常用SQLite命令</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2017 &mdash; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Tiimor</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a></div>




        
<div class="busuanzi-count">
  <!-- modify by zhangwei -->
  <!-- 修改不蒜子统计脚本 -->
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>



<script>
  	var _mtac = {};
  	(function() {
  		var mta = document.createElement("script");
  		mta.src = "https://pingjs.qq.com/h5/stats.js?v2.0.4";
  		mta.setAttribute("name", "MTAH5");
  		mta.setAttribute("sid", "500425805");

  		var s = document.getElementsByTagName("script")[0];
  		s.parentNode.insertBefore(mta, s);
  	})();
</script>


  <script type="text/javascript">
    (function() {
      var hm = document.createElement("script");
      hm.src = "//tajs.qq.com/stats?sId=61441764";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  







<!-- LOCAL: You can save these files to your site and update links -->
    
        
        <link rel="stylesheet" href="https://aimingoo.github.io/gitmint/style/default.css">
        <script src="https://aimingoo.github.io/gitmint/dist/gitmint.browser.js"></script>
    
<!-- END LOCAL -->

    

    
      <script type="text/javascript">
      function renderGitment(){
        var gitment = new Gitmint({
            <!-- modify by zhangwei -->
            <!-- 修复gitment评论页初始化错误@tiimor -->
            id: '1497771674000', 
            owner: 'VeiZhang',
            repo: 'veizhang.github.io',
            
            lang: "" || navigator.language || navigator.systemLanguage || navigator.userLanguage,
            
            oauth: {
            
            
                client_secret: '9919bc61413a89ea3eb156910d282e3103093e32',
            
                client_id: 'f08924ca58e61d6f51f4'
            }});
        gitment.render('gitment-container');
      }

      
      renderGitment();
      
      </script>
    







  




  
  
  
  <link rel="stylesheet" href="/lib/algolia-instant-search/instantsearch.min.css">

  
  
  <script src="/lib/algolia-instant-search/instantsearch.min.js"></script>
  

  <script src="/js/src/algolia-search.js?v=5.1.4"></script>



  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("7aBs9I9Y3PjoN6ueX5J3AYQW-gzGzoHsz", "kboycyzaPNAYcUW8AkF3edeW");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  

  

  

  

  
  <!-- modify by zhangwei -->
  <!-- 动态时间小人 -->
  <!-- modify by zhangwei -->
<!-- 动态时间小人 -->
<!-- z-index -1 表示在最底层，不能悬浮也不能点击 -->
<!-- z-index auto 可以点击 -->
<!-- z-index 9999 无限大时，总是在最上层，会影响其他悬浮框 -->
<div id="dg" style="z-index: auto; position: fixed ! important; right: 0px; top: 0px;">  
    <table width 100% style="position: absolute; width:260px; right: 0px; top: 0px;">  
		<div>
			<embed wmode="transparent" src="http://cdn.tiimor.cn/images/dynamic_time.swf" quality="high" bgcolor="#ffffff" width="160" height="70" name="honehoneclock" align="middle" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
		</div>
    </table>  
</div>
  
</body>
</html>
